Skip to main content

Seting up an eGPU on NixOS

·2 mins
An enclosure containing an external graphics card mounted to the leg of a desk
Thunderbolt eGPU enclosure mounted on its custom 3D printed shelf under my desk

As part of migrating from Fedora to NixOS on my personal machines, a difficulty that I encountered was finding a way to get my Thunderbolt eGPU (containing an AMD GPU) to work with my Framework laptop.

On Fedora, my go-to solution has been a handy script called all-ways-egpu, which works by disabling the integrated graphics, thereby forcing the machine to use the external graphics card only. Rather than attempting to package and use such a script on NixOS, I discovered an elegant solution built into NixOS itself: specialisations.

NixOS provides specialisations as a built in way to create multiple bootable configurations with minor changes for each generation. In this case, creating a specialisation in which we disable the integrated graphics kernel module and manually load the module for the external graphics card works perfectly.

This is all the configuration required to add to get this to work:

specialisation = {
  egpu.configuration = {
    system.nixos.tags = ["egpu"];

    boot = {
      # Ensure module for external graphics is loaded
      initrd.kernelModules = [amdgpu];

      # Disable the integrated graphics module
      blacklistedKernelModules = ["i915"];

      kernelParams = [
        "module_blacklist=i915"
        "amdgpu.pcie_gen_cap=0x40000" # Force AMD GPU to use full width (optional)
      ];
    };

    # Use external graphics
    services.xserver.videoDrivers = [amdgpu];
  };
};

To use: simply power cycle the machine, plug in the Thunderbolt cable, select the generation labeled “egpu” on the bootloader, and everything works as expected!